<?php require_once('../connections/con_gl.php'); ?>
<?php
session_start();
//cekAkses($_SESSION[akses],"DD-2-4");
mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT id, katagori FROM gl_katagoriarsip ORDER BY katagori ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);

?>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<link type="text/css" rel="stylesheet" href="../css/jquery.wysiwyg.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.wysiwyg.js"></script>
<script type="text/javascript">
$(function()
  {
	  $('#keterangan').wysiwyg();
  });
</script>
<body style="background:none;padding:8px;">
<?php if(isset($_POST['Save'])) { ?>
<?php
// validasi data
$kat = $_POST['katagori'];
$ars = $_POST['arsip'];
$fars= $_POST['filearsip'];
$ket = $_POST['keterangan'];
$f_tmp = $_FILES['filearsip']['tmp_name'];
$f_nam = str_replace(" ","",strtolower($_FILES['filearsip']['name']));
$f_tip = $_FILES['filearsip']['type'];
if($f_tip=='') {
	$error[] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Pilih file arsip yang ingin diupload !!!';
}
//echo $f_tip;
if (isset($error)) {
?>
<div id="loading" style="color:#FFF;border:solid 1px #F00;padding:5px;background:#F00;"><?php echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />".implode("<br />", $error); ?></div>
<?php }else{ ?>
<div id="loading" style="color:#1a4d80;border:solid 1px #215800;padding:5px;background:#F0FFED;">
<?php
	$query = "insert into gl_arsip values (NULL,'$_GET[id]','$kat','$f_tip','$f_nam','$ket')";
	$f_dest = "../data_arsip/".$f_nam;
	if(copy($f_tmp,$f_dest)) {
		mysql_select_db($database_con_gl, $con_gl);
		if(mysql_query($query, $con_gl)) {
			echo "<img src=\"../images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Tambah Arsip berhasil ...";
			echo "<script>top.opener.location.reload();self.close();</script>";
		}else{
			echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Tambah Arsip gagal, coba lagi !!!";	
		}
	}else{
		echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Tambah Arsip gagal, coba lagi !!!";	
}
?>
</div>
<?php } ?>
<?php } ?>
<h1>Tambah Data Arsip</h1>
<form action="" method="POST" enctype="multipart/form-data" name="add" id="add" >
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Katagori Arsip : </td>
      <td bgcolor="#FFFFFF"><select name="katagori" id="katagori" style="width:200px;">
            <option value="">Pilih Katagori Arsip</option>
            <?php if($totalRows_klas > 0) { do { ?>
            <option value="<?php echo $row_klas['id'];?>"><?php echo $row_klas['katagori'];?></option>
            <?php }while($row_klas = mysql_fetch_assoc($klas)); } ?>
          </select></td>
    </tr>
    <tr valign="top">
      <td width="20%" align="right" bgcolor="#FFFFFF">Upload Arsip :</td>
      <td width="80%" bgcolor="#FFFFFF"><label>
        <input type="file" name="filearsip" id="filearsip" />
      </label></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Keterangan : </td>
      <td bgcolor="#FFFFFF"><label>
        <textarea name="keterangan" cols="85" rows="5" id="keterangan"></textarea>
        <input name="id" type="hidden" id="id" />
        <input name="kontak" type="hidden" id="kontak" value="<?php echo $_GET['id'];?>" />
      </label></td>
    </tr>
    <tr>
      <td align="left" bgcolor="#FFFFFF"><em>*Harus diisi
        <input name="open" type="hidden" id="open" value="<?php echo $_GET['open'];?>" />
      </em></td>
      <td bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan" />
        </label>
        <label>
          <input type="button" name="Button" value="Batal" onClick="javascript:window.close(2000);" />
        </label></td>
    </tr>
  </table>
</form>
</body>